/**
 * 
 */
package ch.comtools.servermanager.ssh.core;

import java.io.Serializable;

import ch.comtools.servermanager.ssh.SSH;

/**
 * @author Roger Dudler <roger.dudler@gmail.com>
 * @version $Id$
 */
public class SessionInfo implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private String host;
	private String user;
	private String password;
	private int port = SSH.DEFAULT_PORT;

	/**
	 * Default.
	 */
	public SessionInfo() {
		// NOOP
	}
	
	/**
	 * Create a {@link SessionInfo} object.
	 * @param host hostname (e.g. localhost)
	 * @param user username (e.g. root)
	 * @param password password
	 * @param port port (default is {@link SSH#DEFAULT_PORT})
	 */
	public SessionInfo(String host, String user, String password, int port) {
		this.setHost(host);
		this.setUser(user);
		this.setPassword(password);
		this.setPort(port);
	}
	
	/**
	 * Create a {@link SessionInfo} object.
	 * @param host hostname (e.g. localhost)
	 * @param user username (e.g. root)
	 * @param password password
	 */
	public SessionInfo(String host, String user, String password) {
		this.setHost(host);
		this.setUser(user);
		this.setPassword(password);
	}
	
	/**
	 * @return
	 */
	public String getHost() {
		return host;
	}
	
	/**
	 * @param host
	 */
	public void setHost(String host) {
		this.host = host;
	}
	
	/**
	 * @return
	 */
	public String getUser() {
		return user;
	}
	
	/**
	 * @param user
	 */
	public void setUser(String user) {
		this.user = user;
	}
	
	/**
	 * @return
	 */
	public String getPassword() {
		return password;
	}
	
	/**
	 * @param password
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	
	/**
	 * @return
	 */
	public int getPort() {
		return port;
	}
	
	/**
	 * @param port
	 */
	public void setPort(int port) {
		if (port > 0) {
			this.port = port;
		}
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof SessionInfo) {
			SessionInfo info = (SessionInfo) obj;
			if (info.getHost().equals(this.getHost()) &&
				info.getUser().equals(this.getUser()) &&
				info.getUser().equals(this.getPassword()) &&
				info.getPort() == this.getPort()) {
				return true;
			}
		}
		return false;
	}

}
